package chapter_13_proxy.force_proxy;

/**
 * @author yaochenglong
 * @date 2017/10/19
 */
public class GamePlayer implements IGamePlayer {

    private String name;

    private IGamePlayer proxy;

    public GamePlayer(String name) {
        this.name = name;
    }

    @Override
    public void login() {
        if(isProxy()){
            System.out.println("登录成功");
        }else{
            System.out.println("请使用代理访问:登录");
        }
    }

    @Override
    public void killBoss() {
        if(isProxy()){
            System.out.println("杀怪");
        }else{
            System.out.println("请使用代理访问:杀怪");
        }
    }

    @Override
    public void upgrade() {
        if(isProxy()){
            System.out.println("升级");
        }else{
            System.out.println("请使用代理访问:升级");
        }
    }

    private boolean isProxy(){
        if(proxy == null) return false;
        return true;
    }

    /**
     * 每次获得 proxy都要重新new？
     * @return
     */
    @Override
    public IGamePlayer getProxy() {
        this.proxy = new GamePlayerProxy(this);
        return proxy;
    }
}
